package main

import (
	"net/http"
	"fmt"
	"encoding/json"
	"log"
	"db_export/model"
	"db_export/util"
	"os"
)

func main() {
	print(len(os.Args))
	print(os.Args)
	if len(os.Args) <= 1 {
		fmt.Print("plase use command:tableInfo、code")
		os.Exit(0)
	}
	action := os.Args[1]
	if "tableInfo" == action {
		model.QueryAllTable()
	} else if "code" == action {
		if len(os.Args) == 3 {
			fmt.Print(os.Args[2])
			util.WriteWord(os.Args[2])
		} else {
			fmt.Print("the command code need arg path!")
		}

	} else {
		fmt.Sprintf("unKnown command:%s,you maybe can use:%s", action, "tableInfo、code")
	}
	fmt.Print("success!")
}

//导出数据库下所有表结构到word
func IndexHandler(w http.ResponseWriter, r *http.Request) {
	model.QueryAllTable()
	bytes, err := json.Marshal(map[string]interface{}{"flag": 1, "msg": "success"})
	if err != nil {
		log.Fatal("handel request Faite")
	}
	fmt.Fprintf(w, string(bytes))
}
//
////读取某个文件夹下所有代码写入word中
//func CodeWriteHandler(w http.ResponseWriter, r *http.Request) {
//	queryForm, err := url.ParseQuery(r.URL.RawQuery)
//	if err != nil {
//		fmt.Fprintln(w, "error")
//	}
//	requestBody := r.GetBody
//	print(requestBody)
//	util.WriteWord(queryForm["path"][0])
//
//	bytes, err := json.Marshal(map[string]interface{}{"flag": 1, "msg": "success"})
//	if err != nil {
//		log.Fatal("handel request Faite")
//	}
//	fmt.Fprintf(w, string(bytes))
//}
